package XianCheng.交错打印;

import java.util.Scanner;

public class Again_and_Again {
      /*
            三个A和五个B交错打印一直不停
       */
      public static void main(String[] args) {
//            Scanner scanner=new Scanner(System.in);
//            System.out.println("请输入想要循环的次数：");
//            int scan=scanner.nextInt();
            while (true) {
                  Thread t1 = new Thread(new Runnable() {
                        @Override
                        public void run() {
                              try {
                                    Thread.sleep(1000);
                              } catch (Exception e) {
                                    e.printStackTrace();
                              }
                              System.out.print("A");
                        }
                  });

                  Thread t2 = new Thread(new Runnable() {
                        @Override
                        public void run() {
                              try {
                                    Thread.sleep(1000);
                              } catch (Exception e) {
                                    e.printStackTrace();
                              }
                              System.out.print("B");
                        }
                  });

                  Thread t3 = new Thread(new Runnable() {
                        @Override
                        public void run() {
                              try {
                                    Thread.sleep(1000);
                              } catch (Exception e) {
                                    e.printStackTrace();
                              }
                              System.out.print("C");
                        }
                  });

                  t1.start();
                  try {
                        t1.join();
                  } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                  }

                  t2.start();
                  try {
                        t2.join();
                  } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                  }
                  t3.start();
                  try {
                        t3.join();
                  } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                  }
            }
      }
}

